Skip to main content

All Questions

4votes
1answer
83views

Efficient way to win points in chocolate bowl game

I'm working on an optimization problem involving a turn-based chocolate-sharing game, and I need help optimizing my current brute-force solution. Problem Description: You and your friend take turns ...
CodeCrusader's user avatar
4votes
2answers
959views

LeetCode 3366: Minimum Array Sum - w/o DP/memoisation

This program tried to solve LeetCode problem 3366: Minimum Array Sum. It fails for k odd, op1+op2 high enough such there are more odd value to optionally subtract k from than subtractions to allot. A ...
greybeard's user avatar
4votes
1answer
140views

Efficient polynomial multiplication in Python

I'm practicing problems for the ICPC competition, and one of the problems requires solving it by using an FFT to compute the product of two polynomials efficiently. Since this is for the ICPC ...
João Areias's user avatar
6votes
2answers
448views

Family, felon & fuzz River Crossing challenge

I first saw this challenge when a user posted it to SO about two years ago without a shred of code. The post's plea, "How do I get started?" meant the user's post didn't survive long on that ...
Fe2O3's user avatar
  • 4,657
3votes
1answer
237views

Leetcode: Number of Islands - BFS (Queue vs Recursion)

I was playing around with leetcode's Number of Islands. As per the challenge's description: Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the ...
ccot's user avatar
  • 361
3votes
2answers
95views

Optimizing a Function to Check Pronic Numbers in JavaScript

I've written a function in JavaScript to check whether a given number is a Pronic number. A Pronic number, also known as an oblong number, rectangular number, or ...
TAHER El Mehdi's user avatar
9votes
2answers
613views

Advent of code 2023 day 5 in Java: mapping integer ranges to new integer ranges

Context I'll be passing an interview coding test in java soon. I am experienced with other programming languages but am very unfamiliar with Java. I am looking for critiques of the coding style much ...
Stef's user avatar
  • 322
6votes
3answers
465views

Leetcode: Largest Number

I was trying out leetcode's Largest Number. As per the challenge's description: Given a list of non-negative integers nums, arrange them such that they form the largest number and return it. Since ...
ccot's user avatar
  • 361
4votes
2answers
513views

Leetcode: Steps to Make Array Non-decreasing

I was trying out leetcode's Steps to Make Array Non-decreasing As per the challenge's description: You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i ...
ccot's user avatar
  • 361
9votes
4answers
2kviews

Leetcode : First Missing Positive

I was trying out leetcode's first missing positive. As per the challenge's description: Given an unsorted integer array nums, return the smallest missing positive integer. You must implement an ...
ccot's user avatar
  • 361
2votes
1answer
98views

HackerRank Algorithm Problem: Climbing the Leaderboard (Python)

Here is the Hackerrank problem which is related to dense ranking and below is my solution which didn't pass the time limit cases. Any better way to optimize this? ...
peternish's user avatar
2votes
5answers
299views

Sum of bitwise XOR of each subarray weighted by length

here is the problem statement You are given an array a of length n consisting of non-negative integers. You have to calculate the value of \$\sum_{l=1}^n \sum_{r=l}^n f(l,r)\cdot (r - l + 1)\$ where \...
Gurnoor Singh's user avatar
3votes
1answer
363views

Python function to find the count of digits of numerals in base n up to a given limit

This is a simple exercise to find the count of digits of all numerals in a given base up to a given limit (not including the limit), I wrote it to determine the ratio of bytes saved when the numbers ...
Ξένη Γήινος's user avatar
7votes
2answers
1kviews

Find all combinations of length 3 whose sum is divisible by a given number

I came up with a suitable solution to a HackerRank problem that failed because the execution took longer than 10 seconds on lists that were of very large size. The problem: Given a list ...
NFeruch - FreePalestine's user avatar
1vote
2answers
718views

Find the cheapest flight to reach from source to destination

As the input you get the flight schedule as an array, each element of which is the price of a direct flight between 2 cities ...
meallhour's user avatar

153050per page
close